package com.hust360.percent.adapter;

import java.util.ArrayList;

import com.hust360.percent.R;
import com.hust360.percent.pojo.Area;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class AreaListAdapter extends BaseAdapter  {
	
	private Context context;
	private LayoutInflater inflater;
	private ArrayList<Area> list;
	
	public AreaListAdapter(Context context) {
		super();
		this.context = context;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return 15; //list == null? 0 : list.size();
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public Object getItem(int position) {
		return list.get(position);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.area_list_item, null);
			holder = new ViewHolder();
			holder.img = (ImageView) convertView.findViewById(R.area_list_item.image);
			holder.text = (TextView) convertView.findViewById(R.area_list_item.text);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (list != null &&position < list.size() ) {
			Area area = list.get(position);
			holder.text.setText(area.getTitle());
		}
		return convertView;
	}

	public ArrayList<Area> getList() {
		return list;
	}

	public void setList(ArrayList<Area> list) {
		this.list = list;
	}
	
	private class ViewHolder{
		ImageView img;
		TextView text;
	}
}
